//
//  Team9CommunityViewController.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/12.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9CommunityViewController.h"
#import "Team9discussViewController.h"
#import "Team9renovateViewController.h"
#import <MBProgressHUD.h>
#import <Masonry.h>

@interface Team9CommunityViewController ()

@property (nonatomic, strong) UISegmentedControl *seg;
@property (nonatomic, strong) Team9renovateViewController *renovateVC;
@property (nonatomic, strong) Team9discussViewController *dissVC;

@end

@implementation Team9CommunityViewController


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if ([Team9EveningType shareEvening].eveningFailling) {
        self.seg.tintColor = [UIColor greenColor];
        
    }else{
        self.seg.tintColor = [UIColor orangeColor];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.navigationController.navigationBar.translucent = NO;
    self.tabBarController.tabBar.translucent = NO;
    [self createSegMentControl];
    
    
    self.seg.selectedSegmentIndex = 0;
    [self.view bringSubviewToFront:self.renovateVC.view];
    
}

#pragma mark 懒加载
- (Team9renovateViewController *)renovateVC{
    if (!_renovateVC) {
        self.renovateVC = [[Team9renovateViewController alloc] init];
        self.renovateVC.vc = self;
        [self addChildViewController:self.renovateVC];
        [self.view addSubview:self.renovateVC.view];
    }
    return _renovateVC;
}

- (Team9discussViewController *)dissVC{
    if (!_dissVC) {
        self.dissVC = [[Team9discussViewController alloc] init];
        self.dissVC.vc= self;
        [self addChildViewController:self.dissVC];
        [self.view addSubview:self.dissVC.view];
    }
    return _dissVC;
}

#pragma mark 创建seg
- (void)createSegMentControl{
    self.seg =  [[UISegmentedControl alloc] initWithItems:@[@"装修吧", @"讨论区"]];

    [self.navigationController.navigationBar addSubview:self.seg];
    [self.seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
    self.seg.tintColor = [UIColor orangeColor];
    
    self.navigationItem.titleView = self.seg;
}

#pragma mark seg点击方法
- (void)segAction:(UISegmentedControl *)seg{
    if (seg.selectedSegmentIndex == 0) {
        [self.view bringSubviewToFront:self.renovateVC.view];
    }else{
        [self.view bringSubviewToFront:self.dissVC.view];
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
